﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WeChat.Common;
using BLL;
using Models;
using System.Collections.Generic;
using System.Security.Cryptography;
using WxPayAPI;
using System.Text;
using Newtonsoft.Json;
using WeChat.HTTP_Helper;

namespace WeChat
{
    public partial class Binding : System.Web.UI.Page
    {
        BindIdBLL bd = new BindIdBLL();
        public static string wxEditAddrParam { get; set; }
        public string openid_wechat = "";
        public string option = "";
        protected void Page_Load(object sender, EventArgs e)
        {

            //获取到修改信息,进行同步
            //string CAMPUS_NAMES = ConfigurationSettings.AppSettings["CAMPUS_NAME"];
            //string CAMPUS_IDS = ConfigurationSettings.AppSettings["CAMPUS_ID"]; //园区ID		
            //string CORP_IDS = ConfigurationSettings.AppSettings["CORP_ID"];     //合作方ID	 
            //string key_urlS = ConfigurationSettings.AppSettings["key_url"];//密钥url
            //string Request_LinkS = ConfigurationSettings.AppSettings["Request_Link"];//请求链接
            //string Sign = ConfigurationSettings.AppSettings["ccbSafeParam"];
            //string deciphering_url = ConfigurationSettings.AppSettings["deciphering_url"];//密钥url
            //string platform = Context.Request["platform"];
            //string ccbSafeParamBZ = Context.Request["ccbSafeParamBZ"];//获取到跳转参数
            //var context03 = new { key = Sign, data = ccbSafeParamBZ };
            //string data03 = JsonConvert.SerializeObject(context03);
            //ApplicationLog.Write("token_data03:" + data03);
            //string ccbSafeParams03 = WebapiHelper.PostWebRequest(deciphering_url, data03, "", Encoding.GetEncoding("UTF-8"));
            //Dictionary<object, object> jspay_info_keys03 = JsonConvert.DeserializeObject<Dictionary<object, object>>(ccbSafeParams03);
            //ApplicationLog.Write("jspay_info_key:" + jspay_info_keys03);
            //string ccbSafeParam03 = jspay_info_keys03["data"].ToString();
            //ApplicationLog.Write("获取到4.4.1. 解析用户付款码加密密钥：" + ccbSafeParam03);
            //string[] sArray = ccbSafeParam03.Split(new char[2] { '&', '=' });
            //string[] sArray = ccbSafeParamBZ.Split(new char[2] { '&', '=' });

            //测试顺序参数
            //string CUST_ID = sArray[1];
            //string CUST_NAME = sArray[5];
            //string CID_NO = sArray[7];
            //string CAMPUS_ID = sArray[3];
            //string PHONE_NO = sArray[9];
            //string TIMESTAMP = sArray[11];

            //正式环境数据
            //string CUST_ID = sArray[1];
            //string CUST_NAME = sArray[3];
            //string CID_NO = sArray[5];
            //string CAMPUS_ID = sArray[7];
            //string PHONE_NO = sArray[9];
            //string TIMESTAMP = sArray[11];

            //{"key":"8ov4tGn9fMARtCKlLzJqYN1y0KyV9ZM8","data":"h9EOun1F2FxNum94DuFjkS3IxBxK,Tk4SFWhvF6SMAQJoOKZath89sBmZKeE4zp/7gWTP7eG6T29\ncDaCQnEqXO9s5xvIRcISwoRoEqLXGkMe147q60Fw,3j0QxXNylO/ugcHamsyT7TUv7fJZcZXQCl3\nlFI5Wl1Er85L3fVh3/X8NckiLj9PKTwd1Xw9Pea8H6K6Lp5LJR0pyMGUPyQ4AJtFbga4daZChbhd\nz4fSP1rGRM47g3ubCan0sAMziHK52reaJ0hK5bqRlSCvbLmCaAJ,KV/DzULQevGpA9KzEFF0aOgm\nfQPrZg=="}


            // CUST_ID = 100010078 & CAMPUS_ID = 220000003 & CUST_NAME = asdf & CID_NO = 00000023 & TIMESTAMP = 20230922212021022
            //测试数据
            string CUST_ID = "105063663";
            string CUST_NAME = "ZSF";
            string CID_NO = "10086";
            string CAMPUS_ID = "220000353";
            string PHONE_NO = "14715585953";
            string TIMESTAMP = "20230606142933232";

            ////string CUST_ID = "674001";
            ////string CUST_NAME = "李淑波";
            ////string CID_NO = "41072519991003721X";
            ////string CAMPUS_ID = "220000353";
            ////string PHONE_NO = "18238780767";
            ////string TIMESTAMP = "20230606142933232";
            //ApplicationLog.Write("获取到截取参数：CUST_ID:" + CUST_ID + ",CUST_NAME:" + CUST_NAME + ",CID_NO:" + CID_NO + ",CAMPUS_ID:" + CAMPUS_ID + ",PHONE_NO:" + PHONE_NO + ",TIMESTAMP:" + TIMESTAMP);

            //获取到修改信息,进行同步
            //string CAMPUS_NAMES = ConfigurationSettings.AppSettings["CAMPUS_NAME"];
            //string CAMPUS_IDS = ConfigurationSettings.AppSettings["CAMPUS_ID"]; //园区ID		
            //string CORP_IDS = ConfigurationSettings.AppSettings["CORP_ID"];     //合作方ID	 
            //string key_urlS = ConfigurationSettings.AppSettings["key_url"];//密钥url
            //string Request_LinkS = ConfigurationSettings.AppSettings["Request_Link"];//请求链接
            //string Sign = ConfigurationSettings.AppSettings["ccbSafeParam"];
            //string deciphering_url = ConfigurationSettings.AppSettings["deciphering_url"];//密钥url
            ////string platform = Context.Request["platform"];
            //string ccbSafeParamBZ = Context.Request["ccbSafeParamBZ"];//获取到跳转参数
            //ApplicationLog.Write("农安实验学校获取到对应参数值ccbSafeParamBZ:" + ccbSafeParamBZ);
            //string ccbSafeParams03 = HttpUtility.UrlDecode(ccbSafeParamBZ);
            //ApplicationLog.Write("农安实验学校解码获取到参数值ccbSafeParams03:" + ccbSafeParams03);
            ////var context03 = new { key = Sign, data = ccbSafeParamBZ };
            ////string data03 = JsonConvert.SerializeObject(context03);
            ////ApplicationLog.Write("token_data03:" + data03);
            ////string ccbSafeParams03 = WebapiHelper.PostWebRequest(deciphering_url, data03, "", Encoding.GetEncoding("UTF-8"));
            //Dictionary<object, object> jspay_info_keys03 = JsonConvert.DeserializeObject<Dictionary<object, object>>(ccbSafeParams03);
            //ApplicationLog.Write("农安实验学校jspay_info_key:" + jspay_info_keys03);
            //string ccbSafeParam03 = jspay_info_keys03["data"].ToString();
            //ApplicationLog.Write("农安实验学校获取到4.4.1. 解析用户付款码加密密钥：" + ccbSafeParam03);
            ////string[] sArray = ccbSafeParam03.Split(new char[2] { '&', '=' });
            //string[] sArray = ccbSafeParamBZ.Split(new char[2] { '&', '=' });

            ////测试顺序参数
            //string CUST_ID = sArray[1];
            //string CUST_NAME = sArray[5];
            //string CID_NO = sArray[7];
            //string CAMPUS_ID = sArray[3];
            //string PHONE_NO = sArray[9];
            //string TIMESTAMP = sArray[11];
            //ApplicationLog.Write("农安实验学校获取到截取参数：CUST_ID:" + CUST_ID + ",CUST_NAME:" + CUST_NAME + ",CID_NO:" + CID_NO + ",CAMPUS_ID:" + CAMPUS_ID + ",PHONE_NO:" + PHONE_NO + ",TIMESTAMP:" + TIMESTAMP);



            //同步余额
            DataTable Consumptionrestriction = IdentityBLL.Consumption_restriction(CUST_ID, "ryxx");//获取表信息
            if (Consumptionrestriction.Rows.Count > 0)
            {
                //现金余额
                double ready_money = Consumptionrestriction.Rows.Count == 0 ? 0 : (Convert.ToDouble(Consumptionrestriction.Rows[0]["grye"]));
                //补贴余额
                double subsidy_money = Consumptionrestriction.Rows.Count == 0 ? 0 : (Convert.ToDouble(Consumptionrestriction.Rows[0]["btye"]));
                //同步客户现金余额
                double inquire_ready_money = 0;
                //同步客户补贴余额
                double inquire_subsidy_money = 0;
                //查询余额判断是否需要进行修改同步余额
                DataTable dns = IdentityBLL.Select_CUST_ID(CUST_ID);

                if (dns.Rows.Count > 0)
                {
                    //#region 同步余额

                    //string CUST_IDN = dns.Rows[0]["bankcard"].ToString();//用户ID
                    //ApplicationLog.Write("进入到4.2.5. 查询余额方法！");
                    //Dictionary<string, string> pairs = new Dictionary<string, string>();
                    //pairs.Add("CAMPUS_ID", CAMPUS_IDS);
                    //pairs.Add("CORP_ID", CUST_IDN);
                    //pairs.Add("TXCODE", "VIAC05");
                    //pairs.Add("CUST_ID", CUST_ID);//用户ID		

                    //string Signparam = GetSignContent01(pairs);
                    ////     ApplicationLog.Write("获取到参数：" + Signparam);
                    //var context01 = new { key = Sign, data = Signparam };
                    //string data = JsonConvert.SerializeObject(context01);
                    ////       ApplicationLog.Write("token_data:" + data);
                    //string ccbSafeParams = WebapiHelper.PostWebRequest(key_urlS, data, "", Encoding.GetEncoding("UTF-8"));
                    //Dictionary<object, object> jspay_info_keys = JsonConvert.DeserializeObject<Dictionary<object, object>>(ccbSafeParams);
                    ////  ApplicationLog.Write("jspay_info_key:" + jspay_info_keys);
                    //string ccbSafeParam = jspay_info_keys["data"].ToString();
                    //ApplicationLog.Write("获取到加密密钥：" + ccbSafeParam);

                    //Dictionary<string, string> pairs01 = new Dictionary<string, string>();
                    //pairs01.Add("CCB_IBSVersion", "V6");
                    //pairs01.Add("PT_STYLE", "8");
                    //pairs01.Add("PT_LANGUAGE", "CN");
                    //pairs01.Add("CAMPUS_ID", CAMPUS_IDS);
                    //pairs01.Add("CORP_ID", CORP_IDS);
                    //pairs01.Add("TXCODE", "VIAC05");
                    //pairs01.Add("CUST_ID", CUST_IDN);//用户ID		
                    //pairs01.Add("ccbSafeParam", ccbSafeParam);

                    //string context02 = GetSignContent01(pairs01);
                    //ApplicationLog.Write("获取到用户信息请求参数：" + context02);
                    ////测试地址：http://121.40.54.232:8090/CCBIS/B2CMainPlat_00_ZHST
                    ////生产环境：https://dining.icenter.ccb.com/CCBIS/B2CMainPlat_00_ZHST
                    //string Response = WebapiHelper.PostWebRequest(Request_LinkS + context02, "", "", Encoding.GetEncoding("UTF-8"));
                    ////获取回调返回值
                    //ApplicationLog.Write("获取值Response：" + Response);
                    //Dictionary<object, object> jspay_info_key = JsonConvert.DeserializeObject<Dictionary<object, object>>(Response);
                    ////  ApplicationLog.Write("jspay_info_key:" + jspay_info_key);
                    ////响应结果Y：成功 N：失败	
                    //string RESULT = jspay_info_key["RESULT"].ToString();
                    //ApplicationLog.Write("RESULT:" + RESULT);
                    ////获取到数组返回的ACC_NO编码值
                    //string ACC_DATA = jspay_info_key["ACC_DATA"].ToString();
                    //ApplicationLog.Write("ACC_DATA:" + ACC_DATA);
                    //List<StockDto> lists = new List<StockDto>();
                    //lists = JsonConvert.DeserializeObject<List<StockDto>>(ACC_DATA);
                    //foreach (var item in lists)
                    //{
                    //    ApplicationLog.Write("进入到页面item！");
                    //    StockDto A = new StockDto();
                    //    A.ACC_TYPE = item.ACC_TYPE;
                    //    A.MONEY = item.MONEY;
                    //    var ACC_TYPE = A.ACC_TYPE;
                    //    var MONEY = A.MONEY;

                    //    if (ACC_TYPE == "01")
                    //    {
                    //        inquire_ready_money = Convert.ToDouble(MONEY);
                    //    }
                    //    else if (ACC_TYPE == "02")
                    //    {
                    //        inquire_subsidy_money = Convert.ToDouble(MONEY);
                    //    }
                    //}

                    //// ApplicationLog.Write("获取到对应金额inquire_ready_money：" + inquire_ready_money + ",inquire_subsidy_money:" + inquire_subsidy_money);
                    ////判断客户金额与本地金额是否一致
                    //if (Convert.ToDouble(ready_money) == Convert.ToDouble(inquire_ready_money) && Convert.ToDouble(subsidy_money) == Convert.ToDouble(inquire_subsidy_money))
                    //{
                    //    //ApplicationLog.Write("金额一致，无需修改！");
                    //}
                    //else
                    //{
                    //    //不一致修改金额同步
                    //    var Num = IdentityBLL.Up_ACC_DATA(CUST_ID, inquire_ready_money, inquire_subsidy_money);
                    //}


                    //#endregion


                    //查询人员信息登录
                    if (!string.IsNullOrEmpty(PHONE_NO) && !string.IsNullOrEmpty(CUST_NAME) && !string.IsNullOrEmpty(CUST_ID))
                    {
                        // ApplicationLog.Write("进入到判断页面！");
                        DataTable rxtable = this.bd.verifyUser_Tel(PHONE_NO, CUST_NAME, CUST_ID);
                        ApplicationLog.Write("进入到判断页面：" + rxtable.Rows.Count);
                        if (rxtable.Rows.Count > 0)
                        {
                            string seleOpenid = IdentityBLL.getOpenId_Tel(PHONE_NO);//通过手机号查找openid
                            ApplicationLog.Write("查询openid值：" + seleOpenid);
                            //非微信浏览器打开
                            if (seleOpenid == "")
                            {
                                string randomName = Binding.RandomName;
                                IdentityBLL.insertIdbind_Tel(PHONE_NO, CUST_NAME, CUST_ID, randomName, "");
                                this.Session["openid"] = randomName;
                                this.Session["UserName"] = CUST_NAME;
                                base.Response.Redirect("index.html");
                            }
                            else
                            {
                                this.Session["openid"] = seleOpenid;
                                base.Response.Redirect("index.html");
                            }
                        }
                        else
                        {
                            ApplicationLog.Write("登录有误、信息异常PHONE_NO:" + PHONE_NO + ",CUST_ID:" + CUST_ID);
                        }
                    }
                    else
                    {
                        ApplicationLog.Write("登录有误、信息异常");
                        //this.notice.InnerText = "登录信息异常/非建投APP进入！";
                    }
                }
                else
                {
                    base.Response.Redirect("Error_page.html");
                }

            }
            else
            {
                base.Response.Redirect("Error_page.html");
            }



            #region 注释
            //string userAgent = Request.UserAgent;
            //string UA = base.Request["UA"] == null ? "" : base.Request["UA"];//用户身份标识
            //int wechatstate = ConfigurationSettings.AppSettings["wechatstate"] == null ? 0 : Convert.ToInt32(ConfigurationSettings.AppSettings["wechatstate"]);
            //if (userAgent.ToLower().Contains("micromessenger") && wechatstate == 1)
            //{
            //    //微信浏览器打开
            //    JsApiPay jsApiPay = new JsApiPay(this);
            //    if (ViewState["openid"] == null || ViewState["openid"].ToString() == "")
            //    {
            //        try
            //        {
            //            //调用【网页授权获取用户信息】接口获取用户的openid和access_token
            //            jsApiPay.GetOpenidAndAccessToken();
            //            //获取收货地址js函数入口参数
            //            wxEditAddrParam = jsApiPay.GetEditAddressParameters();
            //            openid_wechat = jsApiPay.openid;
            //            ApplicationLog.Write("加载授权获取真实的openid_wechat=" + openid_wechat);
            //            ViewState["openid"] = openid_wechat;
            //            DataSet ds = bd.getUserInfo3(openid_wechat.ToString());

            //            if (ds.Tables[0].Rows.Count == 0)
            //            {
            //            }
            //            else
            //            {
            //                string seleOpenid = ds.Tables[0].Rows[0]["openid"].ToString();
            //                ApplicationLog.Write("获取openid值01：" + seleOpenid);
            //                this.Session["openid"] = seleOpenid;
            //                this.Session["rfkh"] = ds.Tables[0].Rows[0]["rfkh"].ToString();

            //                //跳转对应管理页面
            //                if (UA.Contains("操作员"))
            //                {
            //                    base.Response.Redirect("MerchantManagement/index.html");
            //                }
            //                else
            //                {
            //                    base.Response.Redirect("index.html");
            //                }
            //            }
            //        }
            //        catch (Exception ex)
            //        {
            //            ApplicationLog.Write("加载授权获取真实openid_wechat异常信息为=" + ex.Message);
            //            Response.Write("<script>alter('页面加载出错，请关闭重试');</script>");
            //        }
            //    }
            //    else
            //    {
            //        DataSet ds = bd.getUserInfo3(openid_wechat.ToString());

            //        if (ds.Tables[0].Rows.Count == 0)
            //        {
            //        }
            //        else
            //        {
            //            ApplicationLog.Write("获取openid值02：" + ds.Tables[0].Rows[0]["openid"].ToString());
            //            this.Session["openid"] = ds.Tables[0].Rows[0]["openid"].ToString();
            //            this.Session["rfkh"] = ds.Tables[0].Rows[0]["rfkh"].ToString();
            //            //跳转对应管理页面
            //            if (UA.Contains("操作员"))
            //            {
            //                base.Response.Redirect("MerchantManagement/index.html");
            //            }
            //            else
            //            {
            //                base.Response.Redirect("index.html");
            //            }
            //        }
            //    }

            //}
            //else
            //{
            //    //非微信浏览器打开
            //    if (Request.Cookies["CardId"] != null && Request.Cookies["UserName"] != null && Request.Cookies["Password"] != null)
            //    {

            //        this.CardId.Text = HttpContext.Current.Server.UrlDecode(Request.Cookies["CardId"].Value);
            //        this.UserName.Text = HttpContext.Current.Server.UrlDecode(Request.Cookies["UserName"].Value);
            //        this.PassWord.Attributes["value"] = HttpContext.Current.Server.UrlDecode(Request.Cookies["Password"].Value);

            //        string CardId = HttpContext.Current.Server.UrlDecode(base.Request["CardId"]);
            //        string UserName = HttpContext.Current.Server.UrlDecode(base.Request["UserName"].ToString());
            //        // string text = IdentityBLL.getRfkh(CardId);//通过编号获取卡号
            //        string pwd = HttpContext.Current.Server.UrlDecode(base.Request["password"].ToString());

            //        string randomName = Binding.RandomName;
            //        // List<BanDing> bindingSele = IdentityBLL.getBindingSele(text);
            //        string seleOpenid = IdentityBLL.getOpenId(CardId);

            //        ApplicationLog.Write("CardId:" + CardId + "UserName:" + UserName + "pwd:" + pwd);

            //        DataTable rxtable = this.bd.verifyUser(CardId, UserName, pwd, "");

            //        //判断账户密码是否正确
            //        if (rxtable.Rows.Count == 0)
            //        {

            //            this.notice.InnerText = "用户名或密码输入错误，请重新填写";
            //            return;
            //        }

            //        if (!(randomName != seleOpenid))
            //        {
            //            this.notice.InnerText = "请重新登陆！";
            //            return;
            //        }
            //        if (rxtable.Rows.Count > 0)
            //        {
            //            // int userno = (Int32)rxtable.Rows[0]["userno"];//判断是否管理员身份
            //            if (seleOpenid == "")
            //            {
            //                if (UA.Contains("操作员"))
            //                {
            //                    ApplicationLog.Write($"管理员：{UserName}登录");
            //                }
            //                else
            //                {
            //                    IdentityBLL.insertIdbind(CardId, UserName, pwd, randomName, "");

            //                }
            //            }
            //            if (seleOpenid == "")
            //            {
            //                this.Session["openid"] = randomName;
            //                this.Session["UserName"] = UserName;
            //            }
            //            else
            //            {
            //                this.Session["openid"] = seleOpenid;
            //            }
            //            //跳转对应管理页面
            //            // if (userno > 0)
            //            if (UA.Contains("操作员"))
            //            {
            //                base.Response.Redirect("MerchantManagement/index.html");
            //            }
            //            else
            //            {
            //                base.Response.Redirect("index.html");
            //            }
            //            return;
            //        }
            //        this.notice.InnerText = "该用户状态，账号，用户名，密码是否有误，请重新填写";
            //    }
            //    else
            //    {
            //        ApplicationLog.Write("当前没有保存账号密码信息");
            //        this.CardId.Text = string.Empty;
            //        this.UserName.Text = string.Empty;
            //        this.PassWord.Attributes["value"] = string.Empty;
            //    }
            //}
            #endregion
        }


        //生成openid
        public static string RandomName
        {
            get
            {
                return new string(
                    Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-", 23)
                    .Select(s =>
                    {
                        var cryptoResult = new byte[4];
                        new RNGCryptoServiceProvider().GetBytes(cryptoResult);
                        return s[new Random(BitConverter.ToInt32(cryptoResult, 0)).Next(s.Length)];
                    })
                    .ToArray());
            }
        }
        //用户绑定
        //protected void binding(object sender, EventArgs e)
        //{

        //    string CardId = base.Request["CardId"];
        //    string UserName = base.Request["UserName"].ToString();
        //    //string text = IdentityBLL.getRfkh(CardId);//通过编号获取卡号
        //    string pwd = base.Request["PassWord"].ToString();
        //    string Ycode = base.Request["Ycode"];
        //    string UA = base.Request["UA"];//用户身份标识
        //    string validateCode = Session["validateCode"] == null ? "" : Session["validateCode"].ToString();
        //    ApplicationLog.Write($"Ycode={Ycode},validateCode={validateCode}");
        //    if (Ycode == validateCode)
        //    {



        //        string randomName = Binding.RandomName;
        //        // List<BanDing> bindingSele = IdentityBLL.getBindingSele(CardId);//通过卡号获取姓名和ryid
        //        string seleOpenid = IdentityBLL.getOpenId(CardId);//通过卡号查找openid
        //        if (!(randomName != seleOpenid))
        //        {
        //            this.notice.InnerText = "请重新登陆！";
        //            return;
        //        }
        //        DataTable rxtable = this.bd.verifyUser(CardId, UserName, pwd, UA);
        //        if (rxtable.Rows.Count > 0)
        //        {
        //            Response.Cookies["CardId"].Expires = DateTime.Now.AddDays(-1);
        //            Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
        //            Response.Cookies["PassWord"].Expires = DateTime.Now.AddDays(-1);
        //            //保存账户密码
        //            if (CheckBox1.Checked)
        //            {
        //                ApplicationLog.Write("Id:" + CardId + "Name:" + UserName + "pwd:" + pwd + "当前用户已选择记住密码");
        //                //cookies存储库标识

        //                Response.Cookies["CardId"].Value = HttpContext.Current.Server.UrlEncode(CardId);
        //                Response.Cookies["CardId"].Expires = DateTime.MaxValue;
        //                Response.Cookies["UserName"].Value = HttpContext.Current.Server.UrlEncode(UserName);
        //                Response.Cookies["UserName"].Expires = DateTime.MaxValue;
        //                Response.Cookies["PassWord"].Value = HttpContext.Current.Server.UrlEncode(pwd);
        //                Response.Cookies["PassWord"].Expires = DateTime.MaxValue;

        //            }
        //            else
        //            {
        //                ApplicationLog.Write("Id:" + CardId + "Name:" + UserName + "pwd:" + pwd + "当前用户未操作记住密码，下次需要重新输入账号密码登录！");
        //                //cookies存储库标识
        //                Response.Cookies["CardId"].Expires = DateTime.Now.AddDays(-1);
        //                Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
        //                Response.Cookies["PassWord"].Expires = DateTime.Now.AddDays(-1);

        //            }



        //            string userAgent = Request.UserAgent;
        //            int wechatstate = ConfigurationSettings.AppSettings["wechatstate"] == null ? 0 : Convert.ToInt32(ConfigurationSettings.AppSettings["wechatstate"]);
        //            if (userAgent.ToLower().Contains("micromessenger") && wechatstate == 1)
        //            {
        //                //微信浏览器打开
        //                if (UA.Contains("操作员"))
        //                {
        //                    ApplicationLog.Write($"管理员：{UserName}登录");
        //                }
        //                else
        //                {
        //                    IdentityBLL.insertIdbind(CardId, UserName, pwd, randomName, ViewState["openid"].ToString());

        //                }
        //                this.Session["rfkh"] = CardId;
        //                if (seleOpenid == "")
        //                {
        //                    this.Session["openid"] = randomName;
        //                    this.Session["UserName"] = UserName;

        //                }
        //                else
        //                {
        //                    this.Session["openid"] = seleOpenid;
        //                }
        //                //跳转对应管理页面
        //                if (UA.Contains("操作员"))
        //                {
        //                    base.Response.Redirect("MerchantManagement/index.html");
        //                }
        //                else
        //                {
        //                    base.Response.Redirect("index.html");
        //                }

        //            }
        //            else
        //            {
        //                //非微信浏览器打开
        //                if (seleOpenid == "")
        //                {
        //                    if (UA.Contains("操作员"))
        //                    {
        //                        ApplicationLog.Write($"管理员：{UserName}登录");
        //                    }
        //                    else
        //                    {
        //                        IdentityBLL.insertIdbind(CardId, UserName, pwd, randomName, "");

        //                    }

        //                }
        //                if (seleOpenid == "")
        //                {
        //                    this.Session["openid"] = randomName;
        //                    this.Session["UserName"] = UserName;
        //                }
        //                else
        //                {
        //                    this.Session["openid"] = seleOpenid;
        //                }
        //                //跳转对应管理页面
        //                if (UA.Contains("操作员"))
        //                {
        //                    base.Response.Redirect("MerchantManagement/index.html");
        //                }
        //                else
        //                {
        //                    base.Response.Redirect("index.html");
        //                }
        //            }


        //            return;
        //        }
        //        this.notice.InnerText = "该账户状态，账号，用户名，密码是否有误，请重新填写";
        //        this.CardId.Text = string.Empty;
        //        this.UserName.Text = string.Empty;
        //        this.PassWord.Text = string.Empty;
        //    }
        //    else
        //    {
        //        this.notice.InnerText = "验证码输入不正确，请重新输入！";
        //    }
        //}


        public static string GetSignContent01(IDictionary<string, string> parameters)
        {
            // 第一步：把字典按Key的字母顺序排序
            IDictionary<string, string> sortedParams = new SortedDictionary<string, string>(parameters);
            sortedParams = (from enty in sortedParams orderby enty.Value ascending select enty).ToDictionary(p => p.Key, p => p.Value);
            IEnumerator<KeyValuePair<string, string>> dem = sortedParams.GetEnumerator();

            // 第二步：把所有参数名和参数值串在一起
            StringBuilder query = new StringBuilder("");
            while (dem.MoveNext())
            {
                string key = dem.Current.Key;
                string value = dem.Current.Value;
                if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                {
                    query.Append(key).Append("=").Append(value).Append("&");
                    //query.Append(value).Append("&");
                }
            }
            string content = query.ToString().Substring(0, query.Length - 1);

            return content;
        }

        public class StockDto
        {
            public string ACC_TYPE { get; set; }
            public string ACC_NO { get; set; }
            public string ACC_NAME { get; set; }
            public string MONEY { get; set; }

        }
    }
}
